package huawei;

public class Question3 {

    public long minSumInArrays(int[] array1, int[] array2, int k) {
        long minSum = 0;

        int i = 0;
        int j = 0;

        for (int k1 = 0; k1 < k; k1 ++) {
            minSum += array1[i] + array2[j];
            if (i + 1 < array1.length && j + 1 < array2.length) {
                if (array1[i + 1] < array2[j + 1]) {
                    i += 1;
                } else {
                    j += 1;
                }
            } else if (i + 1 < array1.length) {
                i += 1;
            } else {
                j += 1;
            }
        }

        return minSum;
    }

    public static void main(String[] args) {
        int[] array1 = new int[]{1, 1, 2};
        int[] array2 = new int[]{1, 2, 3};
        int k = 2;

        Question3 question3 = new Question3();
        System.out.println(question3.minSumInArrays(array1, array2, k));
    }
}
